<template>
  <el-dialog :close-on-click-modal='false' v-drag :title="$t('添加')" :v-if="dialogVisible" :visible.sync="dialogVisible" width="400px" top="20vh" @close='close'>
    <div class="dialogContentBoxMaxHeight60">
      <el-form ref="form" :model="record" label-width="70px" :rules="rules" label-position="left" style="margin:0 20px;">
        <el-form-item label="VLAN Id" prop="iVlanId">
          <el-input v-emoji v-model="record.iVlanId" size="small" :placeholder="$t('请输入（1-4094，例如：1，3，5-10）')"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submit">{{$t('确 定')}}</el-button>
      <el-button @click="close">{{$t('取 消')}}</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { addVlanData } from '@/api/network/vlan'
export default {
  name: 'vlanDialog',
  data () {
    var validateIVlanId = (rule, value, callback) => {
      if (String(value).trim() === '') {
        callback(new Error(this.$t('请输入VLAN Id')))
      } else {
        callback()
      }
    }
    return {
      dialogVisible: false,
      record: {
        iVlanId: ''
      },
      rules: {
        iVlanId: [{ required: false, validator: validateIVlanId, trigger: 'blur' }]
      }
    }
  },
  methods: {
    init () {
      this.dialogVisible = true
    },
    submit () {
      this.$refs.form.validate((valid) => {
        if (valid) {
          addVlanData(this.record).then(res => {
            if (res.status === 0) {
              this.$message({
                message: this.$t('添加成功'),
                type: 'success'
              })
              this.close()
              this.$parent.listData()
            }
          })
        }
      })
    },
    close () {
      this.record.iVlanId = ''
      this.dialogVisible = false
      this.$refs.form.resetFields()
    }
  }
}
</script>
